%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calcul de l'erreur globale par patch Dirichlet sur un element
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [errGlob] = Err_globale_patch_Dirichlet_element(donnees, uhloc, maillageIniLoc, subdivision,poutre,sautMomloc,sautEffloc)

l1 = maillageIniLoc(2) - maillageIniLoc(1);
l2 = maillageIniLoc(3) - maillageIniLoc(2);

newMaillage1 = [maillageIniLoc(1):l1/subdivision:maillageIniLoc(2)];
newMaillage2 = [maillageIniLoc(2):l2/subdivision:maillageIniLoc(3)];
newMaillage = [newMaillage1(1:end-1),newMaillage2];


K = AssemblageRigidite(newMaillage,poutre);

C = [1,zeros(1,2*length(newMaillage)-1);
    0,1,zeros(1,2*length(newMaillage)-2);
    zeros(1,2*length(newMaillage)-2),1,0;
    zeros(1,2*length(newMaillage)-1),1];

Klag = [K,C';C,zeros(4)];

F = [zeros(2*(length(newMaillage1)-1),1);sautEffloc;sautMomloc;zeros(2*(length(newMaillage2)-1),1)];
F = F + second_membre_lineique(donnees,newMaillage) ;

Flag=[F;0;0;0;0];


errGlobVect = Klag\Flag;
errGlobVect = errGlobVect(1:length(errGlobVect)-4);
errGlob = F'*errGlobVect;

end